Passed
Branch master (27f176)
by refat
18:17
created

Characters.isCharsString   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
export default class Characters {
2
  constructor(value, object = {}) {
3
    this.object = object;
4
    this.chars = '';
5
    this.times = 0;
6
    this.atFirst = null;
7
    this.atEnd = null;
8
    this.between = null;
9
    this.langsRegex = '';
10
    this.languages = '';
11
    this.value = value || null;
12
  }
13
14
  isObject() {
15
    return (typeof this.object === 'object' && Object.keys(this.object).length);
16
  }
17
18
  isCharsString() {
19
    return (typeof this.chars === 'string');
20
  }
21
22
  isCharsAnArray() {
23
    return Array.isArray(this.chars);
24
  }
25
26
  canCharsSeparateViaComma() {
27
    return this.char.match(/,/) && this.char.match(/,/g).length > 1;
28
  }
29
30
  formatCharsViaComma($comma) {
31
    if ($comma) {
32
      this.chars = this.chars.split(',');
33
    } else {
34
      this.chars = this.chars.split('');
35
    }
36
    return `\\${this.chars.join('\\')}`;
37
  }
38
39
  formatCharsString() {
40
    return this.formatCharsViaComma(this.canCharsSeparateViaComma());
41
  }
42
}
43